var format = require('date-format')
const STATUS = {
  0: '未支付',
  1: '已支付',
  '-2': '已取消'
}
const TYPE = {
  store: '门店收款码',
  '0.52%': 'POS机'
}
export default {
  Deposit: {
    list: {
      export: {
        query: {
          '@display': `{
            'id' : 'entity.getId()',
            'user' : 'entity.getUser().getUsername()',
            'invoice' : 'entity.getInvoice().__toString()',
            'amount' : 'entity.getAmount()',
            'status' : '{ 0: "未支付", 1: "已支付" }[entity.getStatus()]',
            'type' : '{ "liansheng": "联胜接口", "fuiou-pos": "富友POS机接口", "0.7%": "pos机(0.7费率)" }[entity.getType()]',
            'createdTime' : 'entity.getCreatedTime().format("Y-m-d H:i:s")'
          }`,
          limit: 10000000
        },
        label: {
          'id': 'id',
          'user': '用户',
          'invoice': '交易',
          'amount': '金额',
          'status': '状态',
          'type': '类型',
          'createdTime': '创建时间'
        }
      },
      list_filter: {
        'invoice.outTradeNo': '交易编号',
        status: Object.assign({ __label: '状态' }, STATUS),
        type: Object.assign({ __label: '类型' }, TYPE),
        'user.id': '入款用户id',
        'user.username': '入款用户',
        beforePaidTime: {
          expression: 'entity.getInvoice().getPaidTime() >= datetime.get(":value")',
          label: '开始时间',
          type: 'datetime'
        },
        afterPaidTime: {
          expression: 'entity.getInvoice().getPaidTime() < datetime.get(":value")',
          label: '结束时间',
          type: 'datetime'
        },
        beforeCreatedTime: {
          expression: 'entity.getCreatedTime() >= datetime.get(":value")',
          label: '创建开始时间',
          type: 'datetime'
        },
        afterCreatedTime: {
          expression: 'entity.getCreatedTime() < datetime.get(":value")',
          label: '创建结束时间',
          type: 'datetime'
        }
      },
      disabled_actions: ['delete', 'new', 'lines', 'edit'],
      query: {
        '@order': 'entity.invoice.paidTime|DESC',
        '@expands': '["entity.invoice"]'
      },
      list_display: [
        'id',
        'user',
        // 'invoice',
        'amount',
        // {
        //   property: 'relatedStore',
        //   label: '门店'
        // },
        {
          property: 'invoice',
          label: '支付状态',
          component: {
            props: ['data'],
            data() {
              return {
                status: STATUS
              }
            },
            render(h) {
              return <div>{this.status[this.data.__metadata.status]}</div>
            }
          }
        },
        {
          property: 'type',
          component: {
            props: ['data'],
            data() {
              return {
                type: TYPE
              }
            },
            render(h) {
              return <div>{this.type[this.data]}</div>
            }
          }
        },
        {
          property: 'invoice.__metadata.paidTime',
          label: '支付时间',
          component: {
            props: ['data'],
            data() {
              return { createdTime: '' }
            },
            created() {
              if (this.data) {
                this.createdTime = format('yyyy-MM-dd hh:mm:ss', new Date(this.data))
              }
            },
            render(h) {
              return <span>{this.createdTime}</span>
            }
          }
        },
        'createdTime'
      ]
    },
    form: {
      fields: [
        'defaultOutAcntNo'
      ]
    }
  }
}

